 <%@ page language="java" import="java.util.*" pageEncoding="utf-8" import="pojo.*,base.*,service.*,java.text.*,java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<html>
  <head>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <style type="text/css">
</style>
<script type="text/javascript" src="../jquery/jquery-1.6.1.js"></script>
<script type="text/javascript" src="../jquery/jquery.validate.min.js"></script>
 
<script >
 function deleteorder(url){
  if(deleteconfirm()){
  location.href=url;
  }
 }
 function deleteconfirm(){
	if(confirm("确认要删除此订单信息？"))
		return true;
	return false;
 }
 function updateOrderStatus(url){
  if(updateconfirm()){
  location.href=url;
  }
 }
 function updateconfirm(){
	if(confirm("确认要更申请退款？"))
		return true;
	return false;
 }
 </script>

  </head>
  
  <body >
<%
	request.setCharacterEncoding("utf-8");
	int id=(Integer)session.getAttribute("id");
	OrderService rs=new OrderService();
    String where=" where memberid="+id+"";         
	
    int size=rs.getALL(where);
    String spageno = request.getParameter("pageno");
    int pageno;//页码
    int pagesize=6;//每页显示行数
    if(spageno==null){ pageno = 1;}//当页码为空时默认为1
    else pageno=Integer.parseInt(request.getParameter("pageno"));//否则为传过来的页码
	try{pageno = Integer.parseInt(spageno);}
	catch(Exception e){}
	Page p1=new Page();
								p1.setTotalRecord(size);
								p1.setCurrentPageNo(pageno);
								p1.setPageSize(pagesize);	
	List<order> list = rs.getOrder(pageno,pagesize,where);//按参数查询	
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
	for(int i=0,length=list.size();i<length;i++){
		list.get(i).setDate(df.format(list.get(i).getTime()));
	}
		
	
%>
 
	<table class="table table-hover">
      <tr>
        <td >订单时间</td>
        <td >订单号</td>
        <td >菜品总数</td>
        <td >消费总额</td>
        <td >订单状态</td>
        <td >操作</td>
      </tr>
<%
	for (order or : list) {
	out.println("<input type='hidden' name='id' value='"+or.getId()+"'>");
	ReviewService asd = new ReviewService();
	int r =or.getId();
    review q = asd.getorderId(r);
    out.println("<tr><td>"+or.getDate()+"</td>");
	out.println("<td><a href='../orderdetails.jsp?coad="+or.getCoad()+"'>"+or.getCoad()+"</a></td>");
	out.println("<td><div align='center'>"+or.getTotalNum()+"</div></td>");
	out.println("<td>"+or.getTotalPrice()+"元</td>");
	if (or.getTradeStatus()==1){
	      out.println("<td>等待确认</td>");
	      out.println("<td><button class='btn btn-danger' type='button' onclick=deleteorder('../action/websiteAction/deleteorder.jsp?id="+or.getId()+"');>删除</button></td></tr>");
	}
	else if (or.getTradeStatus()==2){
	      out.println("<td>已确认  </td>");
	      out.println("<td><a href='pay.jsp?orderid="+or.getId()+"'>付款</a></td></tr>");
	}
	else if (or.getTradeStatus()==3){
	        if(or.getPay()==1){
	         out.println("<td><div align='center'>现场付款   </div></td>");
	         out.println("<td></td></tr>");
	        }
	        else{
	      out.println("<td><div align='center'>网上付款   </div></td>");
	      out.println("<td><button class='btn btn-inverse' type='button' onclick=updateOrderStatus('../action/websiteAction/updateOrderStatus.jsp?id="+or.getId()+"&orderstatus=5'); >申请退款</button></td></tr>");
	}
	}
	
	else if (or.getTradeStatus()==4){
	
	if(q!=null){
	
	out.println("<td>已完成</td>");
	out.println("<td></td></tr>");
	}
	else {
	out.println("<td>已完成 </td>");
    out.println("<td><a href='addReview.jsp?orderid="+or.getId()+"'>填写评论</a></td></tr>");
	}
	}
	else if (or.getTradeStatus()==5){
	out.println("<td>申请退款中</td>");
	out.println("<td><button class='btn btn-inverse' type='button' onclick=updateOrderStatus('../action/websiteAction/updateOrderStatus.jsp?id="+or.getId()+"&orderstatus=3'); >取消</button></td></tr>");
	}
	else if (or.getTradeStatus()==6){
	out.println("<td>被作废</td>");
	out.println("<td></td></tr>");
	}
	}
	
	out.println("<tr><td colspan='9'><h5>共"+p1.getTotalPage()+"页，当前第"+pageno+"页， ---<a href='myorder.jsp?&pageno="+p1.getPrePage()+"'>上一页</a>");
								 out.print("<a href='myorder.jsp?&pageno="+p1.getNextPage()+"'>下一页</a></h5></td></tr>");
%>
	
	
	
</table>

  </body>
</html>
